package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbItemCatMapper;
import com.dongdongshop.mapper.TbItemMapper;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.pojo.TbItemCatExample;
import com.dongdongshop.service.TbItemCatService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TbItemCatServiceImpl implements TbItemCatService {

    //注入mapper
    @Autowired
    private TbItemCatMapper tbItemCatMapper;
    @Autowired
    private TbItemMapper tbItemMapper;

    //查询分类数据
    @Override
    public List<TbItemCat> tbItemCatshow(Long parentId) {
        TbItemCatExample te = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = te.createCriteria();
        criteria.andParentIdEqualTo(parentId);
        return tbItemCatMapper.selectByExample(te);
    }

    //添加分类数据
    @Override
    public void addTbItemCatshow(TbItemCat tbItemCat) {
        tbItemCatMapper.insertSelective(tbItemCat);
    }

    //回显单个分类数据
    @Override
    public TbItemCat echoTbItemCat(Long id) {
        return tbItemCatMapper.selectByPrimaryKey(id);
    }

    //修改分类数据
    @Override
    public void updateTbItemCatshow(TbItemCat tbItemCat) {
        tbItemCatMapper.updateByPrimaryKeySelective(tbItemCat);
    }

    //删除单个分类数据
    @Override
    public void deleteTbItemCat(Long id) {
        tbItemCatMapper.deleteByPrimaryKey(id);
    }

    //根据商品Id查询商品数据
    @Override
    public TbItem selectItemById(Long itemId) {
        return tbItemMapper.selectByPrimaryKey(itemId);
    }
}
